<%@ page language="java" contentType="text/html; charset=utf-8" errorPage="error.jsp"
    pageEncoding="utf-8"%>
    <!--   errorPage="error.jsp 若页面报错，所有错误提交到error.jsp来处理-->
<%@ page import = "com.littleken.db.*,com.littleken.bean.*,java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">响应的字符编码集：<%= response.getCharacterEncoding() %></h3>
	
	<%
		String account = request.getParameter("account");
		String password = request.getParameter("password");
		
		Emp emp = new Emp(account,null,password,null);
		
		boolean flag = DBUtil.selectEmpByAccountAndPassword(emp);
		
		Map<String,Emp> map = DBUtil.map;
		if(flag){
			Object o = application.getAttribute("count");
			if(o == null){
				application.setAttribute("count", 1);
			}else{
				int count = Integer.parseInt(o.toString());
				application.setAttribute("count", (count+1));
			}
			session.setAttribute("account", account);
		%>
		<h3 align="right">访问量：<%= application.getAttribute("count") %></h3>
		<h3 align="right">登录账户：<%= session.getAttribute("account") %></h3>
		<h3 align="center">欢迎来到人事管理系统首页</h3>		
		<hr>
		<table align="center" border="1" width="500px">
			<tr>
					<td>
						账号
					</td>
					<td>
						员工姓名
					</td>
					<td>
						邮箱
					</td>
					<td>
						修改
					</td>
				</tr>
				<%
					for(String key : map.keySet()){
						Emp e = map.get(key);
						%>
													<tr>
								<td>
									<%= e.getAccount() %>
								</td>
								<td>
									<%= e.getName() %>
								</td>
								<td>
									<%= e.getEmail() %>
								</td>
 								<td>
									<!-- 
									相邻两个JSP页面传递数据的时候。通过URL参数的方式来传递数据。
									规则：
									资源?key=value&key=value
									 -->
									<a href="update.jsp?account=<%= e.getAccount() %>&name=<%= e.getName() %>&email=<%= e.getEmail() %>">修改</a>
								</td> 
							</tr>
						
						<% 
					}
				%>
		</table>
		<%	
		}else{
			//out.println("账号不存在或者密码错误");
			throw new Exception("账号不存在或者密码错误");
		}
		
	%>
<%-- 	<%
		out.println(account);
		out.println(password);
	%> --%>
</body>
</html>